package com.SY7Socket;
 
import com.SY7DA.socket.SocketUDPClient;
import com.SY7DA.socket.SocketUDPClient.Ctl_Code_INFO;
import com.SY7DA.socket.SocketUDPClient.SampleDataInfo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SY7SocketActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        Button btnGetSampleStaus = (Button)findViewById(R.id.BTN_GETSAMPLE);
        btnGetSampleStaus.setOnClickListener(new OnClickListener()
        {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int iRet = SocketUDPClient.GetCommunicateStatus();
				Log.v("SYSOCKET","GetCommunicateStatus: "+iRet);
				
				Ctl_Code_INFO config = new Ctl_Code_INFO();
				iRet = SocketUDPClient.Set(config);
				Log.v("SYSOCKET","Set over: "+iRet);
				//sleep
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
				int count = 0;
				while(true)
				{
					count++;
					if(iRet==1)
					{
						iRet = SocketUDPClient.StartSample();
						Log.v("SYSOCKET","StartSample: "+iRet);
						while(SocketUDPClient.GetSampleStatus()!=1)
						{
							try {
								Thread.sleep(10);
							} catch (InterruptedException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						} 
						Log.v("SYSOCKET","GetSampleStatus: "+iRet);
						SampleDataInfo datainfo = SocketUDPClient.ReadSampleData(512*6);
						
						try {
							Thread.sleep(10);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

					if(count>100)
					{
						break;
					}
				}
			
			}
        	
        });
        
        
    }
}